#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define Rep(i,n) for(int i=0;i<(n);++i) 
#define For(i,a,b) for(int i=(a);i<=(b);++i) 
#define ForI(TP,i,coll) for(TP (i)=coll.begin();(i)!=coll.end();(i)++)
#define ForD(i,a,b) for(int i=(a);i>=(b);--i)
#define All(a) a.begin(), a.end()

struct idcal
{
	typedef map<string, int> S2I;
	S2I tagids;
	int getid(const string& s)
	{
		S2I::iterator it=tagids.find(s);
		if(it!=tagids.end())
			return it->second;

		return tagids[s]=tagids.size();
	}
} cal;

typedef basic_string<int> istring;
typedef vector<istring> VIS;

struct node
{
	int tagid;
	vector<node*> subs;
	node(int id):tagid(id){}
};
static node pure_text(-1);

void parse_subs(istream& in, node* par, VIS& vis)
{
	istring str;
	while(in)
	{
		char c;
		in>>c;
		switch(c)
		{
		case '<':
			{
				bool bEndTag=false;
				in>>c;
				if(c=='/')// reach end
				{
					for(in>>c; c!='>';in>>c); // eat up all

					// always return here
					if(str.size()>1)
						vis.push_back(str);

					return;
				}
				else
					in.putback(c);

				string tag;
				for(in>>c; c!='>';in>>c)
					tag+=tolower(c);

				node* p=new node(cal.getid(tag));
				parse_subs(in, p, vis);

				par->subs.push_back(p);
				str.push_back(p->tagid);
			}
			break;
		default:
			{
				while(in.peek()!='<')
					in.get();
				
				par->subs.push_back(&pure_text);
				str.push_back(pure_text.tagid);
			}
			break;
		}
	}
}

node* par_a_html(istream& in, VIS& vis)
{
	char c;
	for(in>>c; c!='>'; in>>c); // skip <html>
	node* p=new node(-2); // root
	parse_subs(in, p, vis);
	return p;
}

struct page{ string url; node* htm; VIS vis;};

int main()
{
	int N;
	vector<page> htms;

	cin>>N; htms.resize(N);
	Rep(i, N)
	{
		cin>>htms[i].url;
		htms[i].htm=par_a_html(cin, htms[i].vis);

		while(cin.peek()=='=')cin.get();
	}
}